<template>
	<view class="content">
		<view style="height: 275rpx;background-color: #1262DB;">
			<view style="height: 40rpx;"></view>
			<view class="wid90 mar bacFFF borRad10">
				<uni-datetime-picker v-model="datetimerange" type="daterange" rangeSeparator="至" @change="changeTime" />
			</view>
			<view class="textCen coFFF mar-top20 foSi30">
				<view>总收益</view>
				<view class="mar-top10">¥{{parseFloat(total_revenue).toFixed(2)}}</view>
			</view>
		</view>
		<!-- disJuB -->


		<scroll-view style="height: calc(100vh - 526rpx);" scroll-y="true" class="scroll-Y" @scrolltolower="lower">
			<view v-if="list.length == 0" class="wh100 dis disAl disJuC">
				<image src="../../static/incomeDetail/wushiju.png" style="width: 197rpx;height: 226rpx;"></image>
			</view>
			<view v-if="list.length != 0" class="foSi30 mar-top20" v-for="(item,index) in list" :key="index">
				<view class="wid90 mar hei60 dis disAl disJuB">
					<view>{{item.createtime|date('Y-m-d H:i:s')}}</view>
					<view style="color: #2088f8;">收益金额<span style="color: red;" v-if="item.status == 2">(已撤回)</span>：￥{{parseFloat(item.income).toFixed(2)}}</view>
				</view>
				<view class="wid90 mar mar-top10" style="font-weight: 600;">订单编号：{{item.id}}</view>
				<view class="wid90 mar mar-top10" style="color: #AEACAC;">{{item.orderdesc}}</view>
				<view style="height: 20rpx;"></view>
				<view class="xhx"></view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: 1,
				list: [],
				datetimerange: [],
				page: 0,
				total_revenue: 0,
				jiance_revenue: '',
				yajin_revenue: '',
				all_revenue: 0,
				last_page: 0
			}
		},
		onLoad() {
			this.dangqian()
		},
		methods: {
			dangqian() {
				this.zhanshi = 0
				var date = new Date()
				var year = date.getFullYear()
				var month = date.getMonth() + 1
				var day = date.getDate()
				this.datetimerange = [year + '-' + month + '-' + day, year + '-' + month + '-' + day]
				this.getuserinfo()
			},
			chengType(index) {
				this.type = index
				this.page = 0
				this.getuserinfo()
			},
			changeTime(e) {
				this.datetimerange = e;
				if (e.length != 0) {
					this.page = 0
					this.getuserinfo()
				}
			},
			getuserinfo() {
				var that = this
				uni.request({
					url: that.global.url + 'api/device/clinic_order_list',
					method: "POST",
					header: {
						'token': uni.getStorageSync('token')
					},
					data: {
						clinic_id: uni.getStorageSync('clinic_id'),
						begintime: this.datetimerange[0],
						endtime: this.datetimerange[1],
						page: this.page,
						type: this.type
					},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							if (that.page == 0) {
								that.list = result.data.data.data
							} else {
								that.list = that.list.concat(result.data.data.data)
							}
							that.last_page = result.data.data.last_page
							that.total_revenue = result.data.today_income
							that.all_revenue = result.data.all_income
							// that.jiance_revenue = result.data.jiance_revenue
							// that.yajin_revenue = result.data.yajin_revenue
						} else {
							uni.showToast({
								title: result.msg,
								icon: 'error'
							})
						}

					}
				})
			},
			lower: function(e) {
				if (this.last_page != this.page + 1) {
					this.page++
					this.getuserinfo()
				}
			},
		},
		filters: {
			/**
			 * 格式化时间戳 Y-m-d H:i:s
			 * @param {Number} timestamp 2023-01-01 19:20:30  
			 * @param {String} format Y-m-d H:i:s
			 * @return {String}
			 */
			date: function(timeStamp, format = 'Y-m-d H:i') {
				let _date = new Date(timeStamp * 1000),
					Y = _date.getFullYear(),
					m = _date.getMonth() + 1,
					d = _date.getDate(),
					H = _date.getHours(),
					i = _date.getMinutes(),
					s = _date.getSeconds();

				m = m < 10 ? '0' + m : m;
				d = d < 10 ? '0' + d : d;
				H = H < 10 ? '0' + H : H;
				i = i < 10 ? '0' + i : i;
				s = s < 10 ? '0' + s : s;

				return format.replace(/[YmdHis]/g, key => {
					return {
						Y,
						m,
						d,
						H,
						i,
						s
					} [key];
				});
			}
		},
	}
</script>

<style>
	.content {}

	.uni-date-x--border {
		height: 90rpx;
	}

	.wh {
		width: 190rpx;
		height: 76rpx;
		border: 1rpx solid #AEACAC;
		color: #AEACAC;
	}
</style>